package com.hyt.it.ogt.controller.ykcj.exam;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.it.ogt.controller.base.BaseController;
import com.hyt.it.ogt.ykcj.common.annotation.Log;
import com.hyt.it.ogt.ykcj.common.core.domain.AjaxResult;
import com.hyt.it.ogt.ykcj.common.enums.BusinessType;
import com.hyt.it.ogt.ykcj.domain.param.EnterpriseExamSaveParam;
import com.hyt.it.ogt.ykcj.domain.param.EnterpriseExamSubjectSaveParam;
import com.hyt.it.ogt.ykcj.service.exam.IExamInfoService;
import com.hyt.it.ogt.ykcj.service.exam.IExamSubjectInfoService;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;

/**
 * 考试科目信息Controller
 * 
 * @author admin
 * @date 2021-06-18
 */
@Api(tags = "exam.12.企业招聘考试考试科目信息", value = "企业招聘考试科目信息请求接口")
@ApiSort(value = 112)
@RestController
@RequestMapping("/enterprise/exam/subjectInfo")
public class EnterpriseExamSubjectInfoController extends BaseController
{
    @Autowired
    private IExamInfoService examInfoService;

    @Autowired
    private IExamSubjectInfoService iExamSubjectInfoService;

    /**
     * 新增/编辑考试科目信息
     * @throws Exception
     */
    @ApiOperation("新增/编辑考试科目信息")
    @Log(title = "考试科目信息", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult add(@RequestBody EnterpriseExamSubjectSaveParam enterpriseExamSubjectSaveParam)
    {
        EnterpriseExamSaveParam enterpriseExamSaveParam = new EnterpriseExamSaveParam();
        BeanUtil.copyProperties(enterpriseExamSubjectSaveParam, enterpriseExamSaveParam);
        examInfoService.insertSubjectInfo(enterpriseExamSaveParam);
        return  AjaxResult.success();
    }

    /**
     * 获取科目详细信息
     * @throws Exception
     */
    @ApiOperation("获取科目详细信息")
    @ApiImplicitParam(name = "id", value = "科目id", dataType = "String", required = true)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(examInfoService.enterpriseExamSubjectDetail(id));
    }

    /**
     * 删除科目
     * @throws Exception
     */
    @ApiOperation("删除科目")
    @Log(title = "删除科目", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        if(StringUtils.isEmpty(id)){
            return AjaxResult.error("参数不能为空");
        }
        iExamSubjectInfoService.deleteEnterpriseSubjectById(id);
        return AjaxResult.success();
    }


}
